//
//  Maintabbar.m
//  oc微博
//
//  Created by 代亚洲 on 16/4/18.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "Maintabbar.h"
#import "UIView+JACKFrameExt.h"


@interface Maintabbar()

@property(nonatomic,strong)UIButton *button;

@end

@implementation Maintabbar

//-(UIButton *)button{
//    
//    if (_button==nil) {
//        _button=[[UIButton alloc]init];
//    }
//    return _button  ;
//}


-(instancetype)initWithFrame:(CGRect)frame{
   self = [super initWithFrame:frame];
    [self setupaddbutton];
    
//    [self.button bringSubviewToFront:self];

    return self;
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
//    设置加号的中心点
    self.button.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
    
//    设置每一个按钮的宽度
    CGFloat itemw = self.frame.size.width/5;
//    记录是哪个item
    int index = 0;
//    NSLog(@"%@",self.subviews);
    for (int i = 0; i<self.subviews.count; i++) {
//        UIBarButtonItem *bu = [[UIBarButtonItem alloc]init];
        UIView *temp = self.subviews[i];
        if ([temp isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
   
            temp.w = itemw;
            if (index==2) {
                index++;
            }
            temp.x  = itemw * index ;
            index++;
        }
    }
//    block 遍历
//    self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//        if([obj isKindOfClass:NSStringFromClass("UITabBarButton")])
//    }
}

-(void)setupaddbutton{
    
    UIButton *add =[[UIButton alloc]init];
    
//    add.imageView.image = [UIImage imageNamed:@"tabbar_compose_icon_add"];
//    设置button的图片 高亮状态 和 普通状态
    [add setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [add setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
//    设置button的背景图片 高亮状态 和 普通状态
    [add setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [add setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    // 内容大多，控件就设置成多大
    [add sizeToFit];
    
//    添加点击事件
    [add addTarget:self action:@selector(didclickbutton) forControlEvents:UIControlEventTouchUpInside];
    
//    添加到tabbar上
    self.button=add;
    
    [self addSubview:add];
    [add bringSubviewToFront:self];
}

-(void)didclickbutton{
    
    NSLog(@"弹出一个控制器");
}



@end
